# http://www.zuanju.net/
# 专剧电影网
import os
import re
import shutil

import requests

from util.headers import get_headers_init_user_agent

root = 'static/专剧电影网/'
if os.path.exists(root):
    shutil.rmtree(root)
os.makedirs(root)


url = 'http://www.zuanju.net/'
response = requests.get(url)
# print(response.status_code)
content = response.content.decode('utf-8')
# print(content)
# items = re.findall(r'<a class="stui-vodlist__thumb lazyload" href="/qq/(.*?)/" title="(.*?)" data-original="https://gimg3.baidu.com/gimg/app=2028&src=img9.doubanio.com/view/photo/s_ratio_poster/public/(.*?).jpg"><span class="play hidden-xs"></span><span class="pic-text text-right">HD</span></a>', content,re.S)
# items = re.findall(r'<a class="stui-vodlist__thumb lazyload" href="/qq/(.*?)/" title="(.*?)" data-original="https://gimg3.baidu.com/gimg/app=2028&src=img9.doubanio.com/view/photo/s_ratio_poster/public/(.*?).jpg"><span class="play hidden-xs"></span><span class="pic-text text-right">更新至7集</span></a>', content,re.S)
items = re.findall(r'<a class="stui-vodlist__thumb lazyload" href="/qq/(.*?)/" title="(.*?)" data-original="https://gimg3.baidu.com/gimg/app=2028&src=img9.doubanio.com/view/photo/s_ratio_poster/public/(.*?).jpg"><span class="play hidden-xs"></span><span class="pic-text text-right">(.*?)</span></a>', content,re.S)
# print(items)
for item in items:
    # print(item)
    title = item[1]
    thumb_url = f'https://gimg3.baidu.com/gimg/app=2028&src=img9.doubanio.com/view/photo/s_ratio_poster/public/{item[2]}.jpg'
    headers = get_headers_init_user_agent()
    headers.update({
        'referer': url
    })
    thumb_response = requests.get(thumb_url, headers=headers)
    with open(f"{root}/{title}_thumb.jpg", "wb") as f:
        f.write(thumb_response.content)